#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include "params.h"
#include "consts256.h"
#include "neon_ntt.h"
#include "util.h"


int main(void)
{
    poly in, out1;
    nttpoly out;
    int16_t gold_ntt[256] = {
    -3049,  1837, -4677,  6207, -7938,   896, -3336, -2342, 
    -7618,  1423,    25,   799,  5490,  -358,  5372, -3939, 
    -5763, -6645,  3553, -3513, -2738,  1360,  4532,  4696, 
    5194, -6385, -8891,  -381,  -716,  7428,  2216, -6679, 
    -3712,  3710,  1541,  2400,   696, -3550, -2579,  2168, 
    -7222,   373, -1923, -1121,  2218, -3517,  1802,  3567, 
    -696, -2370,  2587,  2450,  1288,  3230, -9313,  3006, 
    -2754, -6047,  1365,  -189, -3696, -3285, -3746, -3245, 
    79,  1868,  8270,  5677, -10809, -6709,  2598, 10521, 
    357, -4555, -3769,  2876, -1292,  2659,  2238, -4707, 
    -1399, -8142,  -166, -1993,  1999, -6789,  6046, -1389, 
    6201, -5755,  2071,  8566,  3950,  1125,  2686, -3457, 
    -100, -2966,  -551, -2063,  5378,   -85,  -939,    -9, 
    5052, -1728, -2305,   826, -3851,  5545,   592,   541, 
    -7724, -2012,  4411,  3051,  1196,  -741,  3419,  2833, 
    -1510,  2090, -9425,  1772,   365,  1235, -1540,  2631, 
    -2547,  5722,  3620,  3181, -1472, -3042,  6932,  1685, 
    3615,   361, -4822,   370,   716, -3564, -2033,  4060, 
    10675, -6582,  6906,  7531,  3984, -5714,  2464, -1117, 
    -5583,  2963,  6146, -1128, -2126,  6248, -1173,  -502, 
    4088,  1665,  2030,  1408,  1947, -3106,  1461, -2939, 
    1769,  2345,  1413, -3544,  2534,  3796,  6356,   520, 
    -2328, -2353,   764,  -484, -1711,  2978,   739, -10605, 
    7691, -1285,   327, -1186, -4556,  1316,  3870,   686, 
    -5545, -5397,  1916, -5433,   464, -2421,   374, -11649, 
    7864,  4610, -3998, -8456, -3041,  1553, -4167, -1480, 
    4023, -8161, -9954, -1639, -4002,  6263,  3678, -1223, 
    2388,  9648,   328, -6720, -5361, -8461,  -377, -6162, 
    -8869,  3993,  -984,  3856,  2388,   113,  2013, -1672, 
    5369,   454,  3093, -2909,  4791,  6014, -5271,  2503, 
    -3421, -1727,  1186,  -964,  1398,  4525,  5087,  2312, 
    -1337,   472,  4357,  2569, -2101,   162,  1831, -2277, 

    };
    
    int16_t gold_invntt[256] = {
    4454, -1570,   709,  1089,  5293,  4756,  1035,  1230, 
    1070,  4417,  6018,   563,   189, -3019,   305,   879, 
    -2294,  -993,   601,  2529, -6755, -4143, -3421,  3274, 
    2315, -1766,   595,  2573,  2438,   538, -3790,  -404, 
    -7372,  5655, -7793,  3890,  -927, -1284, -5655,  3047, 
    -9701, -3217, -3875, -8587,  -815,   220,  2097,  6143, 
    2950,  2632, -3336,  3070, -5552, -11966,  -920, -10469, 
    8087, -4140,   194, -4175,   -39, -2159,  4322, -4118, 
    1590, -3473,   842,  5720, -1778, -5616,   724,  5606, 
    -2599, -3334,  3531, -3460, -4063, -3407,   561,  -430, 
    1109, -7422,  5532,  -123, -2498,  -507, -1479,  3469, 
    4265,  4328,   249, -3835,   294, -1397,  4586, -2801, 
    -575, -6753,  -417,  1958, -2499,  3665, -6234, -2686, 
    1620,  1440,  5259,  5694, -5822,  3270, -1873,  1486, 
    -1764,   824, -2593, -2439,  3110,  2224,  -408,  5515, 
    -2902, -4936, -2035,  1787, -2767,  3067,  1599,  4322, 
    3034, -1876,  2038,  3545,  3422,   522, -2026,  -361, 
    846, -1653,   304, -1554,  2347,  3609, -1786,  3886, 
    815, -2508, -2188,  4036, -2493, -2996,  3466,  -394, 
    -2708,  2494,  2689,  3394,  3198,  -914,    28,  -996, 
    203,  2110, -3807,   960,  -988,   235, -3565, -2064, 
    -1317,  2346, -2048, -2108, -2505,  3531, -3761,   335, 
    -4015, -2888,  3799, -2429,   140,   887,  3370, -2714, 
    -1846, -1252,  3411,  2059,  1544, -2701, -3731,  3449, 
    -1820,  1670, -3510, -2395,   671,  -865,  1860, -2409, 
    -2571, -2662,  1159, -1938, -2315,  1714, -1882, -2169, 
    -471,  -361,  3170, -2955, -3931,  2921,  3344,  1939, 
    1092,  2866, -3915,  2500,  1585, -3409,  -214,   135, 
    -3305,  1049,  3023, -3070, -1771,    20, -2266,  2605, 
    -430,  1204, -1700,  3388,   275,  3624, -3568, -2667, 
    -1400,  2587, -3761,   580,  -636,  2953,  -123,  1635, 
    2152,    57,  3683,  -771, -1089, -2007,  1892,   525, 

    };
    srand(0);
    
    printf("srand(0) in MacOS is different than in Linux\n");
    
    for (int16_t i = 0; i < 256; i++){
        in.coeffs[i] = rand() % P7681;
    }

    neon_ntt(&out, &in, PDATA7681);

    if (compare_array(out.coeffs, gold_ntt)){
        printf("NTT ERROR\n");
        return 1;
    }
    printf("NTT OK\n");


    neon_invntt(&out1, &in, PDATA7681);
    
    if (compare_array(out1.coeffs, gold_invntt)){
        printf("INV NTT ERROR\n");
        return 1;
    }
    printf("INVNTT OK\n");

    return 0;
}
